package mini_v340

import java.util

import io.gatling.core.Predef.{exec, _}
import io.gatling.core.structure.ChainBuilder
import io.gatling.http.Predef._
import conf._

import scala.util.parsing.json._
/**
  * Created by chenbo on 2018/9/6.
  */
object Shopping {

  def shopping:ChainBuilder= exec(
      Request.get( Config.Shopping )
        .check( jsonPath("$..msg").is("success") )
        .check( jsonPath("$..orderId").saveAs("orderId") )
        .check( jsonPath("$.value.deliveryTypeList[*].value").ofType[Int].findAll.saveAs("value") )  // value -> Vector(-1, 1, 2, 3)
    )
//    .exec(session=>session.set("value",JSON.parseFull(session("value").as[String]).get.asInstanceOf[Seq[String]]))


  def ship_time:ChainBuilder={

    var a:Map[String,Any]=Map("itemType"->"1")
    a+=("value"->"1")
    a+=("orderId"->"${orderId}")

    exec(
      Request.put(Config.Shopping_ShipTime,a)
        .check( jsonPath("$..msg").is("success"))
    )
  }

  def shopping_create_order:ChainBuilder={

    var a:Map[String,Any]=Map("orderId"->"${orderId}")
    a+=("payPasswd"->"")
    a+=("printPrice"->"true")

    exec(
      Request.post(Config.Shopping,a)
        .check( jsonPath("$..msg").is("success"))
        .check( jsonPath("$..soSysNo").saveAs("soSysNo"))
    )
  }

  def Pay:ChainBuilder={

    val a:Map[String,String]=Map("orderSysNo"->"${soSysNo}")

    exec(
      Request.post(Config.Pay_UnifiedGoPay+"?OrderSysNo=${soSysNo}",a)
        .check( jsonPath("$..msg").is("success"))
        .check( jsonPath("$..soSysNo").saveAs("soSysNo"))
    )
  }
}
